﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>WinWaitActive / WinWaitNotActive - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The WinWaitActive and WinWaitNotActive functions wait until the specified window is active or not active." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>WinWait[Not]Active</h1>

<p>Waits until the specified window is active or not active.</p>

<pre class="Syntax"><span class="func">WinWaitActive</span> <span class="optional">WinTitle, WinText, Timeout, ExcludeTitle, ExcludeText</span>
<span class="func">WinWaitNotActive</span> <span class="optional">WinTitle, WinText, Timeout, ExcludeTitle, ExcludeText</span></pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>WinTitle</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a>, <a href="../Concepts.htm#numbers">整数</a>或<a href="../Objects.htm">对象</a></p>
    <p>识别目标窗口的窗口标题或其他条件. 请参阅 <a href="../misc/WinTitle.htm">WinTitle</a>.</p>
  </dd>

  <dt>WinText</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>如果存在, 此参数必须是目标窗口的单个文本元素的子字符串(和内置的 Window Spy 工具显示的一样). 如果 <a href="DetectHiddenText.htm">DetectHiddenText</a> 为 ON, 那么会检测隐藏文本元素.</p>
  </dd>

  <dt>Timeout</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a>或<a href="../Concepts.htm#numbers">浮点数</a></p>
    <p>How many seconds to wait before timing out and returning 0. Leave blank to allow the function to wait indefinitely. Specifying 0 is the same as specifying 0.5.</p>
  </dd>

  <dt>ExcludeTitle</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>标题中含有此参数值的窗口将被排除.</p>
  </dd>

  <dt>ExcludeText</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>文本中含有此参数值的窗口将被排除.</p>
  </dd>

</dl>

<h2 id="Return_Value">返回值</h2>
<p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
<p>WinWaitActive returns the <a href="../misc/WinTitle.htm#ahk_id">HWND (unique ID)</a> of the active window if it matches the criteria, or 0 if the function timed out.</p>
<p>WinWaitNotActive returns 1 if the active window does not match the criteria, or 0 if the function timed out.</p>

<h2 id="Remarks">备注</h2>
<p>If the active window satisfies the function's expectation, the function will not wait for <em>Timeout</em> to expire. Instead, it will immediately return, allowing the script to resume.</p>
<p>Since <code>"A"</code> matches whichever window is active at any given moment, <code>WinWaitNotActive "A"</code> typically waits indefinitely. To instead wait for a different window to become active, specify its unique ID as in the following example:</p>
<pre>WinWaitNotActive "ahk_id " WinExist("A")</pre>
<p>Both WinWaitActive and WinWaitNotActive will update the <a href="../misc/WinTitle.htm#LastFoundWindow">Last Found Window</a> if a matching window is active when the function begins or becomes active while the function is waiting.</p>
<p>当函数处于等待状态时, 可以通过<a href="../Hotkeys.htm">热键</a>, <a href="../objects/Menu.htm">自定义菜单项</a>或<a href="SetTimer.htm">计时器</a>启动新的<a href="../misc/Threads.htm">线程</a>.</p>
<p>If another <a href="../misc/Threads.htm">thread</a> changes the contents of any variable(s) that were used for this function's parameters, the function will not see the change -- it will continue to use the title and text that were originally present in the variables when the function first started waiting.</p>
<p>窗口标题和文本是区分大小写的. 除非 <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a> 被打开, 否则不会检测隐藏窗口.</p>
<h2 id="Related">相关</h2>
<p><a href="WinWait.htm">WinWait</a>, <a href="WinWaitClose.htm">WinWaitClose</a>, <a href="WinExist.htm">WinExist</a>, <a href="WinActive.htm">WinActive</a>, <a href="SetTitleMatchMode.htm">SetTitleMatchMode</a>, <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a></p>
<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>Run "notepad.exe"
if WinWaitActive("Untitled - Notepad", , 2)
    WinMinimize  <em>; minimize the window found by WinWaitActive.</em>
else
    MsgBox "WinWaitActive timed out."
</pre>
</div>

</body>
</html>